<script setup>
/**
 * 在外界调用clearEditor方法时，会执行clearEditor函数，清除编辑器内容
 * 
 * <ClearEditor ref="clearEditorRef" />
 * 
 * clearEditorRef.value.clearEditor() 
 */
import { useLexicalComposer } from 'lexical-vue'
import { $getRoot } from 'lexical'

const editor = useLexicalComposer()
const clearEditor = () => {
  editor.update(() => {
    const root = $getRoot()
    root.clear()
  })
}

defineExpose({
  clearEditor
})

</script>